package com.weepal.pavement.mqtt.demo.config.mqtt;

import org.eclipse.paho.client.mqttv3.IMqttClient;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;

public class MqttClientContainer {
    /**
     * 改容器为了对接多个mqtt服务器，根据mqttId获取对应的client
     * 可理解为一个mqtt的多数据源
     */
    private static Map<String, AtomicReference<IMqttClient>> mqttClientMap = new ConcurrentHashMap(8);

    public static AtomicReference<IMqttClient> getClient(String clientId) {
        return mqttClientMap.get(clientId);
    }

    public static AtomicReference<IMqttClient> putClient(String clientId, AtomicReference<IMqttClient> client) {
        return mqttClientMap.put(clientId,client);
    }
}
